<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :defaults.sync="showColumn"
               :permission="permissionList"
               :page.sync="page"
               :before-open="beforeOpen"
               :before-close="beforeClose"
               @sortable-change="sortableChange"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @filter="filterChange"
               @sort-change="sortChange"
               @row-dblclick="handleRowDBLClick"  
               @tree-load="treeLoad"             
               @on-load="onLoad">
      <template slot-scope="scope" slot="menu">
        <el-button type="text"
                   size="small"
                   icon="el-icon-circle-plus-outline"
                  v-if="permission.biz_apparch_system_add"
                   @click.stop="handleAddSub(scope.row)">新增子项
        </el-button>
      </template>
      <template slot-scope="scope" slot="menuForm">
        <div  style="text-align:right; float:right">
          <el-button type="text" v-if="operateType == 'edit'"  icon="el-icon-time" style="font-weight:normal;" size="large" @click.stop="getHistoryRecord">修改历史</el-button>
        </div> 
      </template>
      <template slot-scope="scope" slot="menuLeft">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   v-if="permission.biz_apparch_system_batch_add"
                   @click.stop="openBatchAddDialog">批量新增
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.biz_apparch_system_batch_delete"
                   @click.stop="handleDelete">删 除
        </el-button>
      </template>
      <template slot="menuRight">
        <el-button v-if="permission.biz_apparch_system_download" type="default" @click.stop="exportExcel"  title="下载" icon="el-icon-download" circle size="small"></el-button>
      </template>
    </avue-crud>
    <!-- 
      批量添加数据对话框
     -->
    <el-dialog title="批量导入" width='80%' :close-on-click-modal='false' :visible.sync="batchAddDialog">
      <el-tag>
        ID，
        租户ID，
        上级系统ID，
        上级系统名称，
        系统名称，
        系统简称，
        系统英文名称，
        系统类别，
        系统类型，
        所属部门名称，
        开发部门名称，
        开发团队名称，
        系统负责人，
        系统负责人名，
        <br>
        建设方式，
        建设类型，
        系统版本号，
        系统状态，
        上线日期，
        下线日期，
        系统功能描述，
        架构层级，
        应用群组，
        功能组，
        重要级别，
        安全等级，
        RTO分值，
        RPO分值，
        </br>
        系统运行日期，
        系统运行方式，
        可单独部署标志，
        中间件列表，
        数据库列表，
        项目编号，
        项目名称，
        供应商名称，
        供应商负责人，
        供应商联系电话，
      </el-tag>
      <el-input
        type="textarea"
        :autosize="{ minRows: 10, maxRows: 20}"
        placeholder="请直接从excel粘贴内容"
        v-model="importDataArea">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="handleImport($event)" data-clipboard-target="#pathText">开始导入</el-button>
        <el-button size="small" @click="batchAddDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 历史记录 -->
    <update-history ref="historyRecord"></update-history>
  </basic-container>
</template>

<script>
import {queryGeneralApparchLevelListPage} from '@/api/general/param/generalApparchLevelApi';
import {exportBizApparchSystemExcel,saveOrUpdateBizApparchSystem,saveOrUpdateBizApparchSystemList,saveBizApparchSystem,saveBizApparchSystemList,deleteBizApparchSystem,queryBizApparchSystem,queryBizApparchSystemListPage,updateBizApparchSystem,deleteBizApparchSystemList} from '@/api/biz/apparch/bizApparchSystemApi';
import {mapGetters} from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import {filterFormat} from '@/util/util';
export default {
  data() {
    return {
      //文件选择器的打开方式 add新增、edit修改、view 查看
      openType: 'edit',
      
      // 当前打开form对话框操作类型 
      operateType: 'add',
      
      //修改记录对话框
      historyDialog: false,
      //如果做流程表单 请将次开关设置为true，否则设置为false
      isFlow: true,
      flowArea: {},
      isAddParent: true,
      
      importDataArea: '',
      batchAddDialog: false,
      form: {},
      currentRow: {},
      selectionList: [],
      loading: true, 
      showColumn: [],
      option: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 140,
        dialogTop: '50',
        indexFixed:true, 
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: true,
        addBtn: true,
        addBtnText: '新增主系统',
        viewBtn: false,
        delBtn: false,
        cancelBtn: true,
        printBtn:false,
        saveBtn: true,
        filterBtn:true,          
        menuWidth: 200,
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '70%',
        highlightCurrentRow:  true,
        defaultExpandAll: true,
        searchShow:true,
        lazy:true,
        column: [
          {
            label: '系统/模块名称',
            prop: 'systemNameTmp', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 24,
            width:200,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            display: false,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统/模块编号',
            prop: 'id', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 24,
            width:200,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            display: false,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '架构层级',
            prop: 'architectureLevel', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            width: 120,
            maxlength: 100,
            overHidden: true,
            disabled: false,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 100,
              message: '内容长度不能超过100字符',
            }],
            dicData:[],
            change: ({value,column}) => {
              if(this.isAddParent){
                this.loadBizTypeList('architectureLevel',value);
              }
            }
          },
          {
            label: '应用群组',
            prop: 'appGroup', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 100,
            width: 120,
            overHidden: true,
            disabled: false,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 100,
              message: '内容长度不能超过100字符',
            }],
            dicData:[],
            change: ({value,column}) => {
              if(this.isAddParent){
                this.loadBizTypeList('appGroup',value);
              }
            }
          },
          {
            label: '功能组',
            prop: 'functionGroup', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 100,
            width: 120,
            overHidden: true,
            disabled: false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 100,
              message: '内容长度不能超过100字符',
            }],
            dicData:[],
          },
          {
            label: '上级系统',
            prop: 'parentSystemName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            type: 'input',
            disabled: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 2000,
              message: '内容长度不能超过2000字符',
            }],
          },
          {
            label: '系统/模块类别',
            prop: 'systemCategory', 
            type: 'select', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 120,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统/模块名称',
            prop: 'systemName', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 120,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统/模块简称',
            prop: 'systemShortName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 120,
            multiple: true,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统/模块英文名',
            prop: 'systemEnglishName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          
          {
            label: '系统/模块类型',
            prop: 'systemType', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '所属部门',
            prop: 'belongDeptName', 
            type: 'tree', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            props: {
              label: 'orgName',
              value: 'orgName'
            },
          },
          {
            label: '开发部门',
            prop: 'developDeptName', 
            type: 'tree', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            props: {
              label: 'orgName',
              value: 'orgName'
            },
          },
          {
            label: '开发团队',
            prop: 'developTeamName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '负责人',
            prop: 'systemRespsbUserName', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            width: 120,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            remote: true,
            dicMethod:'get',
            dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
            props: {
              label: 'userName',
              value: 'realName'
            },
          },
          {
            label: '系统负责人名',
            prop: 'systemRespsbRealName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            display: false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '建设方式',
            prop: 'buildWay', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '建设类型',
            prop: 'buildType', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '版本号',
            prop: 'systemVersionNo', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统状态',
            prop: 'systemStatus', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '上线日期',
            prop: 'onlineDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            value: this.$toolUtil.formatDate(new Date()),
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '下线日期',
            prop: 'offlineDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 100,
            overHidden: true,
            value: this.$toolUtil.formatDate(new Date()),
            rules: [{
              validator: (rule, value, callback) => {
                if(value != ''){
                  let onlineDate = this.form.onlineDate;
                  if(value < onlineDate){
                    callback(new Error('下线日期必须大于上线日期'));
                  }
                  else{
                    callback();
                  }
                }
                else{
                  callback();
                }
              },
              required:  false,
              trigger: 'blur'
            },
            {
              max: 100,
              message: '内容长度不能超过100字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统功能描述',
            prop: 'systemFunctionDesc', 
            type: 'textarea', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 24,
            sortable: false,
            hide: true,
            maxlength: 2000,
            overHidden: true,
            maxRows: 3,
            minRows: 3,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 2000,
              message: '内容长度不能超过2000字符',
              trigger: 'blur'
            }],
            dicData:[],
          }, 
          
          {
            label: '重要级别',
            prop: 'importantGrade', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '安全等级',
            prop: 'securityLevel', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 10,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 10,
              message: '内容长度不能超过10字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: 'RTO(分钟)',
            prop: 'rtoScore', 
            type: 'number', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxRows: 10000,
            minRows: 0,
            value: 0,
            overHidden: true,
            rules: [{
              message: '请输入数字',
              required:  true,
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: 'RPO(分钟)',
            prop: 'rpoScore', 
            type: 'number', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxRows: 10000,
            minRows: 0,
            overHidden: true,
            value: 0,
            rules: [{
              message: '请输入数字',
              required:  true,
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '系统运行方式',
            prop: 'systemRunWay', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            width: 100,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '可单独部署标志',
            prop: 'mayAloneDeployFlag', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 1,
            overHidden: true,
            value: '是',
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 1,
              message: '内容长度不能超过1字符',
              trigger: 'blur'
            }],
            dicData:[
              {
                label: '是',
                value: '是'
              },
              {
                label: '否',
                value: '否'
              }
            ],
          },
          {
            label: '中间件列表',
            prop: 'middlewareList', 
            type: 'dynamic',  
            span: 24,
            hide: true,
            children: {
              align: 'center',
              headerAlign: 'center', 
              column: [
                {
                  label: '类型',
                  prop: 'middlewareType',
                  type: 'select',
                  width: 150,
                  rules:[{
                    required:  true,
                    message: '请输入内容',
                  }],
                  dicData: []
                },
                {
                  label: '名称',
                  prop: 'name',
                  type: 'input',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
                {
                  label: '中间件版本',
                  prop: 'version',
                  type: 'input',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
                {
                  label: '是否国产',
                  prop: 'madeInChina',
                  type: 'select', 
                  value: '是',
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[
                    {
                      label: '是',
                      value: '是'
                    },
                    {
                      label: '否',
                      value: '否'
                    }
                  ],
                }, 
              ]
            }
          },
          {
            label: '数据库列表',
            prop: 'databaseList', 
            type: 'dynamic',
            span: 24,
            hide: true, 
            children: {
              align: 'center',
              headerAlign: 'center', 
              column: [
                {
                  label: '数据库类型',
                  prop: 'databaseType',
                  type: 'select',
                  width: 150,
                  rules:[{
                    required:  true,
                    message: '请输入内容',
                  }],
                  dicData: []
                },
                {
                  label: '数据库名称',
                  prop: 'name',
                  type: 'input',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
                {
                  label: '数据库版本',
                  prop: 'version',
                  type: 'input',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
                {
                  label: '是否国产',
                  prop: 'madeInChina',
                  type: 'select',
                  value: '是',
                  rules: [{
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[
                    {
                      label: '是',
                      value: '是'
                    },
                    {
                      label: '否',
                      value: '否'
                    }
                  ],
                }, 
              ]
            }
          },
          {
            label: '标签信息',
            prop: 'labelInfo', 
            type: 'dynamic', 
            span: 24,
            children: {
              align: 'center',
              headerAlign: 'center', 
              column: [
                {
                  label: '标签类型',
                  prop: 'labelType',
                  type: 'select',
                  width: 120,
                  rules:[{
                    required:  true,
                    message: '请输入内容',
                  }],
                  dicData: []
                },
                {
                  label: '标签值',
                  prop: 'labelValues',
                  type: 'select',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    type: 'array',
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
              ]
            }
          },
          {
            label: '供应商名称',
            prop: 'supplierName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '供应商负责人',
            prop: 'supplierRespsbName', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
          {
            label: '供应商联系电话',
            prop: 'supplierContactPhoneNo', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
           	  // 检查电话号码
              validator: (rule, value, callback) => {
                if(value != '' && !this.$validate.isPhone(value)){
                  callback(new Error('请输入有效的电话号码！'));
                }
                else{
                  callback();
                }
              },
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[],
          },
        ]
      },
      data: [],
      // 请求参数区
      formPage: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: [],
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  computed: {
    ...mapGetters(['website','orgTree','genOrgTree','userInfo','permission','projectInfo']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.biz_apparch_system_add, false),
        viewBtn: this.vaildData(this.permission.biz_apparch_system_view, false),
        delBtn: this.vaildData(this.permission.biz_apparch_system_delete, false),
        editBtn: this.vaildData(this.permission.biz_apparch_system_edit, false),
        printBtn: this.vaildData(this.permission.biz_apparch_system_print, false),
        searchBtn:this.vaildData(this.permission.biz_apparch_system_search, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({id : ele.id});
      });
      return ids;
    } 
  },
  methods: {
    /**
     * 获取业务种类列表
     */
    loadBizTypeList(type,value){
      let singleBody = {};
      if(type == 'architectureLevel'){
        this.findObject(this.option.column, 'appGroup').dicData=[];
        this.findObject(this.option.column, 'functionGroup').dicData=[];
        singleBody.architectureLevel = value;
      }
      else if(type == 'appGroup'){
        this.findObject(this.option.column, 'functionGroup').dicData=[];
        singleBody.architectureLevel = this.form.architectureLevel;
        singleBody.appGroup = value;
      }
      if(value == ''){
        singleBody.architectureLevel = '未知层级';
        singleBody.appGroup = '未知层级';
      }
      this.reqParams =  {
        singleBody: singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1, 
        pageSize: this.website.maxPageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryGeneralApparchLevelListPage(this.commonData).then(res => {
        let plateDictList = [];
        let categoryDictList = [];
        const data = res.data.body;
        if(type == 'architectureLevel'){
          data.listBody.forEach(element => {
            //this.$console.log('==JSON.stringify(plateDictList)==',JSON.stringify(plateDictList))
            if(JSON.stringify(plateDictList).indexOf(element.appGroup) < 0){
              plateDictList.push(
                {
                  label: element.appGroup,
                  value: element.appGroup
                },
              );
            }
          });
          if(plateDictList.length == 0){
            plateDictList.push(
              {
                label: '未知应用群组',
                value: '未知应用群组'
              },
            );
          }
          // 如果值不在下拉列表中则置为空
          if(JSON.stringify(plateDictList).indexOf(this.form.appGroup) < 0){
            this.form.appGroup = '';
          }
          this.findObject(this.option.column, 'appGroup').value = '';
          this.findObject(this.option.column, 'appGroup').dicData = plateDictList;


          this.findObject(this.option.column, 'functionGroup').value = '';
          this.findObject(this.option.column, 'functionGroup').dicData = categoryDictList;
        }
        else if(type == 'appGroup'){
          // if(data.listBody.length > 0){
          //   categoryDictList = [];
          // }
          data.listBody.forEach(element => {
            if(JSON.stringify(categoryDictList).indexOf(element.functionGroup) < 0){
              categoryDictList.push(
                {
                  label: element.functionGroup,
                  value: element.functionGroup
                },
              );
            }
          });
          if(categoryDictList.length == 0){
            categoryDictList.push(
              {
                label: '未知功能组',
                value: '未知功能组'
              },
            );
          }
          // 如果值不在下拉列表中则置为空
          if(JSON.stringify(categoryDictList).indexOf(this.form.functionGroup) < 0){
            this.form.functionGroup = '';
          }
          this.findObject(this.option.column, 'functionGroup').value = '';
          this.findObject(this.option.column, 'functionGroup').dicData = categoryDictList;
        }
      }, error => {
      });
    },

    /**
     * 加载树形列表
     */
    treeLoad(tree, treeNode, resolve) {
      this.singleBody = {
        parentSystemId: tree.id
      }
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1, 
        pageSize: 99999
      }
      this.commonData = reqCommonMsg(this.reqParams)
      let childrenList = [];
      queryBizApparchSystemListPage(this.commonData).then(res => {
        childrenList = res.data.body.listBody;
        resolve(childrenList)
      }, error => {
      });
    },

    /**
     * 加载列表数据
     */
    onLoad(page) {
   	  //如果和项目相关，请打开项目ID作为查询条件
      //if(!this.$project.checkChooseProject()){
      //  return false;
      //}
      this.singleBody.parentSystemId = this.userInfo.tenantId,

      this.loading = true;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: page.currentPage, 
        pageSize: page.pageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryBizApparchSystemListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false; 
      });
    },

    /**
     * 新增子项目
     */
    handleAddSub(row){
      this.isAddParent = false;
      this.$refs.crud.rowAdd();
      // 防止加载过快，导致失败。
      setTimeout(()=> {
        this.findObject(this.option.column, 'architectureLevel').disabled = true;
        this.findObject(this.option.column, 'appGroup').disabled = true;
        this.findObject(this.option.column, 'functionGroup').disabled = true;
        this.form.parentSystemId = row.id;
        this.form.parentSystemName = row.systemName;
        this.form.architectureLevel = row.architectureLevel;
        this.form.appGroup = row.appGroup;
        this.form.functionGroup = row.functionGroup;        
      }, 1000);
    },
    /**
     * 新增一条记录
     */
    rowSave(row, done, loading) {
      this.reqParams.singleBody = row;
      let formatUser = {};
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.systemRespsbUserName);
      this.reqParams.singleBody.systemRespsbUserName = formatUser.userId; 
      this.reqParams.singleBody.systemRespsbRealName = formatUser.userName;
      this.commonData = reqCommonMsg(this.reqParams)
      saveBizApparchSystem(this.commonData).then(() => {
        done();
        this.singleBody={};
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        done();
      });         
      //this.$console.log("row = ",row ,loading)
    },
    /**
     * 修改一条记录
     */
    rowUpdate(row, index, done, loading) {
      this.reqParams.singleBody = row;
      let formatUser = {};
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.systemRespsbUserName);
      this.reqParams.singleBody.systemRespsbUserName = formatUser.userId; 
      this.reqParams.singleBody.systemRespsbRealName = formatUser.userName;
      this.commonData = reqCommonMsg(this.reqParams)
      updateBizApparchSystem(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        done();
      });
    },
    /**
     * 删除一条记录
     */
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteBizApparchSystem(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => {});
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick (row, event) {
      if(this.permission.biz_apparch_system_dbclick){
        this.$refs.crud.rowView(row,row.$index);
      }
    },
    /**
     * 批量新增记录
     */
    openBatchAddDialog(){
      this.batchAddDialog = true;
    },
    /**
     * 批量导入
     */
    handleImport() {
      const loading = this.$loading({
        lock: true,
        text: '处理中...',
        spinner: 'el-icon-loading',
      });
      var dataList = new Array();
      if(this.importDataArea){
        var lineList = this.importDataArea.split('\n')
        lineList.forEach((element,index) => {
          if(element.trim() != ''){
            var field = element.split('\t')
            var fieldList = {
              id:field[0].trim(),
              tenantId:field[1].trim(),
              parentSystemId:field[2].trim(),
              parentSystemName:field[3].trim(),
              systemName:field[4].trim(),
              systemShortName:field[5].trim(),
              systemEnglishName:field[6].trim(),
              systemCategory:field[7].trim(),
              systemType:field[8].trim(),
              belongDeptName:field[9].trim(),
              developDeptName:field[10].trim(),
              developTeamName:field[11].trim(),
              systemRespsbUserName:field[12].trim(),
              systemRespsbRealName:field[13].trim(),
              buildWay:field[14].trim(),
              buildType:field[15].trim(),
              systemVersionNo:field[16].trim(),
              systemStatus:field[17].trim(),
              onlineDate:field[18].trim(),
              offlineDate:field[19].trim(),
              systemFunctionDesc:field[20].trim(),
              architectureLevel:field[21].trim(),
              appGroup:field[22].trim(),
              functionGroup:field[23].trim(),
              importantGrade:field[24].trim(),
              securityLevel:field[25].trim(),
              rtoScore:field[26].trim(),
              rpoScore:field[27].trim(),
              systemRunDate:field[28].trim(),
              systemRunWay:field[29].trim(),
              mayAloneDeployFlag:field[30].trim(),
              middlewareList:field[31].trim(),
              databaseList:field[32].trim(),
              projectNo:field[33].trim(),
              projectName:field[34].trim(),
              supplierName:field[35].trim(),
              supplierRespsbName:field[36].trim(),
              supplierContactPhoneNo:field[37].trim(),
            }
            dataList[index] = fieldList
            //this.$console.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        saveBizApparchSystemList(this.commonData).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          loading.close();
        }, error => {
          //this.$console.log(error);
          loading.close();
        });      
      }
      else{
        this.loading=false;
        this.$message({
          type: 'warning',
          message: '数据格式不正确!'
        });
      }
    },
    /**
     * 搜索重置
     */
    searchReset() {
      this.conditions =[];
      this.singleBody = {};
      this.onLoad(this.page);
    },
    /**
     * 搜索
     */
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad(this.page);
      done();
    },
    refreshChange(){
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * 处理批量删除
     */
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteBizApparchSystemList(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        }).catch(() => {});
    },
    /**
     * 拷贝记录
     */
    handleCopy(row){
      this.$confirm('确定复制数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading=true;
        let copyValue=row;
        copyValue.id='0';
        copyValue.dataSign='0'
        copyValue.tableName='拷贝 '+ copyValue.tableName; 
        this.reqParams.singleBody = copyValue;
        this.commonData = reqCommonMsg(this.reqParams)
        saveSysToolTables(this.commonData).then(() => {
          this.singleBody={};
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.loading=false;
        }, error => {
          //this.$console.log(error);
          this.loading=false;
        });
      }).catch(() => {});       
    },
    /**
     * 打开编辑、查询弹窗前查询记录
     */  
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        this.operateType = 'edit';        
        this.reqParams =  {
          singleBody: {
            id:this.form.id
          }
        }
        let commonData = reqCommonMsg(this.reqParams)
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading'
        });
        queryBizApparchSystem(commonData).then(res => {
          this.form = res.data.body.singleBody;
    	    if(res.data.body.singleBody.systemRespsbUserName){
          	this.form.systemRespsbUserName = res.data.body.singleBody.systemRespsbRealName+'('+ res.data.body.singleBody.systemRespsbUserName +')';
          }
          this.form.labelInfo = JSON.parse(this.form.labelInfo);
          this.form.middlewareList = JSON.parse(this.form.middlewareList);
          this.form.databaseList = JSON.parse(this.form.databaseList);
          loading.close();
          done();
        }, error => {
          //this.$console.log(error);
          loading.close();
          done();
        });
      }
      if (['add'].includes(type)) {
        this.operateType = 'add';        
        const loading = this.$loading({
          lock: true,
          text: '加载中...',
          spinner: 'el-icon-loading'
        });
        setTimeout(() => {
          loading.close();
          done();
        }, 500); 
        setTimeout(() => {
          this.form.parentSystemId = this.userInfo.tenantId;
          this.form.parentSystemName = '主系统节点';
        }, 1000); 
      }
    },
    /**
     * 关闭前处理
     */
    beforeClose(done, type){
      if (['add'].includes(type)) {
        this.operateType = 'add';        
        this.findObject(this.option.column, 'architectureLevel').disabled = false;
        this.findObject(this.option.column, 'appGroup').disabled = false;
        this.findObject(this.option.column, 'functionGroup').disabled = false;
        this.isAddParent = true;
      }
      done();
    },
    /**
     * 翻页查询
     */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    /**
     * 更改每页条数
     */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    /**
     * 自定义查询条件
     */
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad(this.page);
    },
    /**
     * 列表排序
     */
    sortChange(val){
      this.orderRules=val
      this.onLoad(this.page);
    },
  
    /**
     * 导出Excel
     */
    exportExcel() {
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage:1, 
        pageSize: 100
      }
      //this.$console.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportBizApparchSystemExcel(this.commonData);
    },
    /**
     * 获取业务字典参数
     */
    async getBizDict() {
      let dicData = await this.$params.getBizDict('["systemStatus","architectureLevel","systemRunWay","systemGrade","buildWay","buildType","importantGrade","securityLevel","middlewareType","databaseType","systemType","labelType","bizSystemLabelValues"]');
      this.findObject(this.option.column, 'systemRunWay').dicData = dicData.systemRunWay;
      this.findObject(this.option.column, 'systemType').dicData = dicData.systemType;
      this.findObject(this.option.column, 'systemStatus').dicData = dicData.systemStatus;
      this.findObject(this.option.column, 'architectureLevel').dicData = dicData.architectureLevel;
      this.findObject(this.option.column, 'systemCategory').dicData = dicData.systemGrade;
      this.findObject(this.option.column, 'buildWay').dicData = dicData.buildWay;
      this.findObject(this.option.column, 'buildType').dicData = dicData.buildType;
      this.findObject(this.option.column, 'importantGrade').dicData = dicData.importantGrade;
      this.findObject(this.option.column, 'securityLevel').dicData = dicData.securityLevel;
      this.findObject(this.option.column, 'middlewareList').children.column[0].dicData = dicData.middlewareType;
      this.findObject(this.option.column, 'databaseList').children.column[0].dicData = dicData.databaseType;
      this.findObject(this.option.column, 'labelInfo').children.column[0].dicData = dicData.labelType;
      this.findObject(this.option.column, 'labelInfo').children.column[1].dicData = dicData.bizSystemLabelValues;
    },
    
    /**
     * 调用子组件方法查询历史
     */
    getHistoryRecord () {
      setTimeout(() => {
        this.$refs.historyRecord.getUpdateHistoryRecord(this.form.id);
      })
    },
  },
  created() {
    //如果和项目相关，请打开
    // if(!this.projectInfo || !this.projectInfo.projectName){
    //   this.$message({
    //     type: 'warning',
    //     message: '请选择一个项目再进入！'
    //   });
    //   this.$router.push({path: '/general/project/generalMyProjectSelector'});
    // }       
    this.showColumn = this.$getStore({name: this.userInfo.userId+'bizApparchSystemColumn'});
    //获取业务字典
    setTimeout(() => {
      this.getBizDict();
    }, 1000);
    
    //加载机构
    let getOrgTreeTimer = setInterval(() => {
      if(this.genOrgTree){
        let orgTree = [];
        this.genOrgTree.forEach(element => {
          if(element.orgType == '1'){
            orgTree.push(element);
          }
        }); 
        this.findObject(this.option.column, 'belongDeptName').dicData = [];
        this.findObject(this.option.column, 'belongDeptName').dicData = this.deepClone(orgTree); 
    
        this.findObject(this.option.column, 'developDeptName').dicData = [];
        this.findObject(this.option.column, 'developDeptName').dicData = this.deepClone(orgTree); 
        clearInterval(getOrgTreeTimer);
      }
    }, 100);
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({name:  this.userInfo.userId+'bizApparchSystemColumn', content: this.showColumn});
      },
      deep: true
      //this.$setStore({name:  this.userInfo.userId+'bizApparchSystemColumn', content: this.showColumn});
    }
  }
};
</script>
